﻿package mortal.game.view.rebate.rank
{
    import Message.Public.*;
    import com.gengine.global.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.events.*;
    import extend.language.*;
    import fl.controls.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.rebate.openServerSevenDay.data.*;
    import mortal.game.view.wizard.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class RebateRankPanel extends BaseWindow
    {
        protected var _bg:ScaleBitmap;
        protected var _tab:GTabarNew;
        protected var _titleBg:ScaleBitmap;
        protected var _nameTitle:GTextFiled;
        protected var _playerTitle:GTextFiled;
        protected var _orderTitle:GTextFiled;
        protected var _riseTitle:GTextFiled;
        protected var _rewardTitle:GTextFiled;
        protected var _list:GTileList;
        protected var _myRankBtn:GButton;
        protected var _orderPower:GTextFiled;
        protected var _tip:GTextFiled;
        protected var _timeTip:GTextFiled;
        private var _tabData:Array;
        private var _nameArr:Array;
        private var _orderArr:Array;
        private static var _instance:RebateRankPanel;
        public static var dayNumOut:int;

        public function RebateRankPanel(param1:ILayer = null)
        {
            this._tabData = Language.getArray(71895);
            var _loc_2:* = Language.getArrayByStr(71896);
            this._nameArr = ["", ""];
            this._nameArr = this._nameArr.concat(_loc_2);
            this._orderArr = Language.getArrayByStr(71897);
            super(param1);
            setSize(756, 535);
            title = "" + Language.getString(71898);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.bg(10, 62, 744, 457, this, ImagesConst.PanelBg);
            this._tab = UIFactory.gTabBarNew(6, 40, this._tabData, 750, 200, 60, 26, this, this.onTabBarChangeHandler);
            this._titleBg = UIFactory.bg(14, 67, 734, 23, this, ImagesConst.RegionTitleBg);
            this._nameTitle = UIFactory.gTextField("", 112, 67, 100, 25, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13).setBold(true));
            this._playerTitle = UIFactory.gTextField("" + Language.getString(71899), 235, 66, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13).setBold(true));
            this._orderTitle = UIFactory.gTextField("", 303, 66, 100, 25, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13).center().setBold(true));
            this._riseTitle = UIFactory.gTextField("" + Language.getString(71900), 515, 67, 100, 25, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13).setBold(true));
            this._rewardTitle = UIFactory.gTextField("" + Language.getString(71901), 581, 66, 150, 25, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13).setBold(true));
            this._list = UIFactory.tileList(17, 101, 722, 370, this);
            this._list.direction = GBoxDirection.VERTICAL;
            this._list.verticalGap = 2;
            this._list.horizontalGap = 2;
            this._list.rowHeight = 37;
            this._list.columnWidth = 707;
            this._list.columnCount = 1;
            this._list.rowCount = 10;
            this._list.width = 722;
            this._list.setStyle("cellRenderer", RebateRankCell);
            this._myRankBtn = UIFactory.gButton("" + Language.getString(71902), 18, 482, 70, 30, this, "GreenLinkButton");
            this._orderPower = UIFactory.gTextField("" + Language.getString(71903), 419, 67, 62, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13).setBold(true));
            this._tip = UIFactory.gTextField("" + Language.getString(71904), 101, 488, 700, 20, this, GlobalStyle.textFormatLv);
            this._timeTip = UIFactory.gTextField("" + Language.getString(71905), 640, 39, 110, 25, this, GlobalStyle.textFormatHuang2.setSize(15));
            this._list.height = 400;
            this._list.verticalScrollPolicy = ScrollPolicy.OFF;
            this._myRankBtn.configEventListener(MouseEvent.CLICK, this.onMyRankCk);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg = null;
            this._tab = null;
            this._titleBg = null;
            this._nameTitle = null;
            this._playerTitle = null;
            this._orderTitle = null;
            this._riseTitle = null;
            this._rewardTitle = null;
            this._list = null;
            this._myRankBtn = null;
            this._orderPower = null;
            this._tip = null;
            this._timeTip = null;
            return;
        }// end function

        private function onTabBarChangeHandler(event:MuiEvent) : void
        {
            var _loc_2:int = 0;
            _loc_2 = this._tab.selectedIndex;
            this.getDataByIndex(_loc_2);
            this._nameTitle.text = "" + this._nameArr[_loc_2];
            this._orderTitle.text = "" + this._orderArr[_loc_2];
            if (_loc_2 < 1)
            {
                this._orderPower.visible = false;
                this._orderTitle.x = 303 + 57;
            }
            else
            {
                this._orderTitle.x = 303;
                this._orderPower.visible = true;
                if (_loc_2 == 2)
                {
                    this._orderPower.text = "" + Language.getString(71906);
                }
                else
                {
                    this._orderPower.text = "" + this._tabData[_loc_2].label + "" + Language.getString(71906);
                }
            }
            return;
        }// end function

        private function getDataByIndex(param1:int) : void
        {
            if (this._tab.selectedIndex != param1)
            {
                this._tab.selectedIndex = param1;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateSevenDayRankGetData, param1));
            return;
        }// end function

        public function getByDayNum(param1:int = -1) : void
        {
            param1 = param1 == -1 ? (dayNumOut) : (param1);
            var _loc_2:int = 0;
            if (OpenServerSevenDayUtil.PowNum == param1)
            {
                _loc_2 = 0;
            }
            else if (OpenServerSevenDayUtil.LevelNum == param1)
            {
                _loc_2 = 1;
            }
            else
            {
                _loc_2 = param1 + 1;
            }
            this.getDataByIndex(_loc_2);
            var _loc_3:* = this._tab.selectedIndex;
            this._nameTitle.text = "" + this._nameArr[_loc_3];
            this._orderTitle.text = "" + this._orderArr[_loc_3];
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show();
            this.x = (Global.stage.stageWidth - this.width) / 2;
            this.y = (Global.stage.stageHeight - this.height) / 2;
            return;
        }// end function

        public function updateDate() : void
        {
            var _loc_1:* = Cache.instance.openServerSevenDay.rankPanelList;
            if (_loc_1.length > 10)
            {
                _loc_1.length = 10;
            }
            var _loc_2:* = new DataProvider(_loc_1);
            this._list.dataProvider = _loc_2;
            return;
        }// end function

        private function onMyRankCk(event:MouseEvent) : void
        {
            var _loc_3:SToplist = null;
            var _loc_6:int = 0;
            var _loc_2:* = Cache.instance.openServerSevenDay.rankPanelList;
            if (_loc_2 == null || _loc_2.length == 0)
            {
                return;
            }
            var _loc_4:* = Cache.instance.role.entityInfo.name;
            var _loc_5:String = "";
            _loc_6 = 0;
            while (_loc_6 < _loc_2.length)
            {
                
                _loc_3 = _loc_2[_loc_6];
                switch(_loc_3.toplistType)
                {
                    case EToplistType._EToplistTypePlayerCombat:
                    case EToplistType._EToplistTypePlayerLevel:
                    {
                        _loc_5 = "" + _loc_3.entityName;
                        break;
                    }
                    case EToplistType._EToplistTypeMountCombat:
                    case EToplistType._EToplistTypeMountRank:
                    case EToplistType._EToplistTypeWing:
                    case EToplistType._EToplistTypeFashion:
                    case EToplistType._EToplistTypeWeapon:
                    case EToplistType._EToplistTypePetGrowth:
                    case EToplistType._EToplistTypeFightSoul:
                    case EToplistType._EToplistTypeFightMethod:
                    {
                        _loc_5 = "" + _loc_3.ownerName + "";
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                if (_loc_4 == _loc_5)
                {
                    break;
                }
                _loc_6++;
            }
            if (_loc_4 == _loc_5)
            {
                if (_loc_6 < _loc_2.length)
                {
                    this._list.selectedIndex = _loc_6;
                }
            }
            else
            {
                MsgManager.showRollTipsMsg("" + Language.getString(71907));
            }
            return;
        }// end function

        public static function get instance() : RebateRankPanel
        {
            if (_instance == null)
            {
                _instance = new RebateRankPanel;
            }
            return _instance;
        }// end function

        public static function get hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
